package dhm.com.dhmshop.adapter.mine;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.MessageListBean;
import dhm.com.dhmshop.entity.ShopOrderBean;
import dhm.com.dhmshop.updata.activity.MessagedetailActivity;
import dhm.com.dhmshop.view.mine.myshop.ShoporderdActivity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder> {

    private List<MessageListBean.DataBean> shopList;
    private Context context;


    public MessageAdapter(Context context) {
        this.shopList = new ArrayList<>();
        this.context = context;
    }


    public void setShopList(List<MessageListBean.DataBean> shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_message, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {

        viewHolder.content.setText(shopList.get(i).getMsgContent());

        if (shopList.get(i).getMsgStatus()==0){
            viewHolder.content.setTextColor(Color.parseColor("#222222"));
        }else {
            viewHolder.content.setTextColor(Color.parseColor("#999999"));
        }

        viewHolder.check.setChecked(shopList.get(i).isChecked());
        viewHolder.check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(compoundButton.isPressed()) {
                    shopList.get(i).setChecked(viewHolder.check.isChecked());
                    onIntentClick.item(shopList);
                }
            }
        });

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, MessagedetailActivity.class);
                intent.putExtra("msgId",shopList.get(i).getId()+"");
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public CheckBox check;
        public TextView content;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            check=itemView.findViewById(R.id.check);
            content=itemView.findViewById(R.id.content);
        }
    }

    private OnClick ondelClick;
    public void setdeleteClick(OnClick onClick) {
        this.ondelClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }


    private OneditClick oneditClick;
    public void seteditClick(OneditClick onClick) {
        this.oneditClick = onClick;
    }
    public interface OneditClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(List<MessageListBean.DataBean> message);
    }



}

